package com.bjbn.controller;

import com.bjbn.service.FlightViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.Map;

/**
 * 航班可视化控制器
 * 
 * @author bjbn
 */
@RestController
@RequestMapping("/api/flight")
public class FlightViewController {

    @Autowired
    private FlightViewService flightViewService;

    /**
     * 实时延误航班统计
     * 
     * @return 延误航班统计数据
     */
    @GetMapping("/delay-stats")
    public Mono<ResponseEntity<Map<String, Object>>> getDelayStatistics() {
        return flightViewService.getDelayStatistics()
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 当前放行正常率
     * 
     * @return 放行正常率数据
     */
    @GetMapping("/release-rate")
    public Mono<ResponseEntity<Map<String, Object>>> getCurrentReleaseRate() {
        return flightViewService.getCurrentReleaseRate()
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 今日航班、旅客量统计
     * 
     * @return 今日航班和旅客量统计数据
     */
    @GetMapping("/today-stats")
    public Mono<ResponseEntity<Map<String, Object>>> getTodayFlightPassengerStats() {
        return flightViewService.getTodayFlightPassengerStats()
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 近一周航班靠桥率
     * 
     * @return 近一周靠桥率数据
     */
    @GetMapping("/weekly-bridge-rate")
    public Mono<ResponseEntity<Map<String, Object>>> getWeekCloseBridgeRate() {
        return flightViewService.getWeekCloseBridgeRate()
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 今年航班、旅客量统计
     * 
     * @return 今年航班和旅客量统计数据
     */
    @GetMapping("/yearly-stats")
    public Mono<ResponseEntity<Map<String, Object>>> getYearFlightPassengerStats() {
        return flightViewService.getYearFlightPassengerStats()
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 健康检查接口
     * 
     * @return 服务状态
     */
    @GetMapping("/health")
    public String health() {
        return "Flight View Api Service is running";
    }
} 